<template>
  <view id="chooseUser">
      <view class="searchPart">
          <input type="text" placeholder="请输入用户ID或昵称" v-model="searchVal">
          <view class="ser" @click="search">搜索</view>
      </view>

      <view class="userList">
          <view class="item" v-for="(item,i) in userList" :key="i" @click="chooseUser(item)">
              <img :src="item.headimg_url" alt="用户头像">
              <view><text>{{item.nickname}}</text> ({{item.uid}})</view>
              
          </view>
      </view>
  </view>
</template>

<script>
export default {
    data(){
        return{
            searchVal:"",
            userList:[]
        }
    },
    mounted(){
        this.getAllUser()
    },
    methods:{
        getAllUser(){
            this.$store.dispatch("getAllUser",{keyword:this.searchVal}).then(res=>{
                if(res.code==1){
                    this.userList = res.data
                }
            })
        },
        search(){
            this.getAllUser()
        },
        chooseUser(item){
            //console.log(item)
            uni.$emit("changeAddress",item)
            // uni.redirectTo({
            //     url:`/pages/order/createOrder/create3`
            // })
            uni.navigateBack({
                delta:1
            });
        }
    }
}
</script>

<style lang="scss" scoped>
#chooseUser{
    .searchPart{
        display: flex;
        justify-content: space-between;
        padding: 20rpx;
        background: #fff;
        align-items: center;
        input{
            background: #edeff7;
            border-radius: 34rpx;
            width: 580rpx;
            height: 60rpx;
            font-size: 28rpx;
            box-sizing: border-box;
            padding-left: 20rpx;
        }
        .ser{
            color:#0077FF;
            font-size: 32rpx;
        }
    }
    .userList{
        background: #fff;
        .item{
            display: flex;
            justify-content: flex-start;
            align-items: center;
            height: 140rpx;
            box-sizing: border-box;
            padding: 0 20rpx;
            img{
                width: 80rpx;
                height: 80rpx;
                margin-right: 20rpx;
            }
            view{
                font-size: 32rpx;
                color: #a4a8b7;
                border-bottom: 1px solid #979797;
                height: 120rpx;
                width: 100%;
                line-height: 120rpx;
                text{
                    color: #262e34;
                    font-weight: bold;
                    margin-right: 10rpx;
                }
            }
        }
    }
}
</style>